package com.cqut.ktpspring.controller;


import com.cqut.ktpspring.pojo.Result;
import com.cqut.ktpspring.service.CourseMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
public class CourseMemberController {
    @Autowired
    CourseMemberService courseMemberService;

    @PostMapping( "/addMember")
    public Result addMember(@RequestParam String cno, @RequestParam String userId) {
        log.info("新增课程成员对象:{},{}",cno,userId);
        courseMemberService.addMember(cno, userId);
        return Result.success();
    }

    @DeleteMapping("/deleteMembers")
    public Result deleteMembers(@RequestParam String cno, @RequestParam List<String> members) {
        log.info("删除课程成员对象:{},{}",cno,members);
        courseMemberService.deleteMembers(cno, members);
        return Result.success();
    }

    @GetMapping("/getCourseMembers")
    public Result getCourseMembers(@RequestParam String cno) {
        log.info("获得某课程的所有成员对象的userId:{}",cno);
        List<String> members=courseMemberService.getCourseMembers(cno);
        return Result.success(members);
    }

    @GetMapping(value = "/getCourse")
    public Result getCourse(@RequestParam String userId) {
        log.info("获得某成员的所有课程对象的cno:{}",userId);
        List<String> courses=courseMemberService.getCourse(userId);
        return Result.success(courses);
    }

    @GetMapping(value = "/getMemberCount")
    public Result getMemberCount(@RequestParam String cno) {
        log.info("获得某门课的成员总数:{}",cno);
        int member_num= courseMemberService.getMemberCount(cno);
        return Result.success(member_num);
    }


}

